package com.baizhiedu.baizhiappsys.service.impl;

import com.baizhiedu.baizhiappsys.dao.UserDao;
import com.baizhiedu.baizhiappsys.dao.impl.UserDaoImpl;
import com.baizhiedu.baizhiappsys.entity.User;
import com.baizhiedu.baizhiappsys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lby
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public Map selectAll() {
        Map map = new HashMap(2);

//        查询数据
        List<User> users = userDao.selectAll();

        map.put("total",users.size());
        map.put("rows",users);
        return map;
    }

    @Override
    public Map selectAllByLimit(Integer offset, Integer limit) {
        Map map = new HashMap(2);

        //获取分页数据
        List<User> users = userDao.selectAllByLimit(offset, limit);

        //获取数据总行数
        Integer total = userDao.selectTotalCount();

        map.put("total",total);
        map.put("rows",users);
        return map;
    }

    @Override
    public Map searchUserByPhone(String searchContext) {
        Map map = new HashMap(2);
        User user = userDao.searchUserByPhone(searchContext);
        //如果出现手机号重复是否返回多个值
        List<User> users = new ArrayList<>();
        users.add(user);
        map.put("total",users.size());
        map.put("rows",users);
        return map;
    }
}
